home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 13524 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.3 KB  |  55 lines

  1. Path: news.ov.com!news
  2. From: glenn@ov.com (Fletcher.Glenn@ov.com)
  3. Newsgroups: comp.lang.c
  4. Subject: Re: accessing structures via pointers
  5. Date: 8 Apr 1996 15:45:32 GMT
  6. Organization: OpenVision
  7. Message-ID: <4kbcas$dir@spanky.pls.ov.com>
  8. References: <1996Apr8.144012.25767@leeds.ac.uk>
  9. Reply-To: glenn@ov.com
  10. NNTP-Posting-Host: foghorn.pls.ov.com
  11.  
  12. In article 25767@leeds.ac.uk, csyamc@scs.leeds.ac.uk (A M Casey) writes:
  13. >Hi I'm calling the function getgrent(), which resturns a structure
  14. >as defined in grp.h, ie
  15. >
  16. > struct group {
  17. >                 char    *gr_name;   /* the name of the group */
  18. >                 char    *gr_passwd; /* the encrypted group password */
  19. >                 gid_t   gr_gid;     /* the numerical group ID */
  20. >                 char    **gr_mem;   /* vector of pointers to member names */
  21. >          };
  22. >the trouble is it returns a pointer to the structure:
  23. >
  24. >struct group *getgrent(void);
  25. >
  26. >
  27. >and I havent got a clue how to access it. I've lookied at the faq, but
  28. >I'm still stuck.
  29. >
  30. >I need something like
  31. >
  32. >printf("the group name is %s\n",tempgroup.gr_name);
  33. >
  34. >but that doesnt work because tempgroup is a pointer.
  35. >
  36. >How do I do this?
  37. >
  38. >Cheers
  39. >
  40. >Andy
  41. >
  42.  
  43.  
  44.  
  45. Try:
  46.  
  47. struct group *gp;
  48.  
  49. gp = getgrent(gid);
  50.  
  51. printf("The group name is %s\n", gp->gr_name);
  52.  
  53.             Fletcher.Glenn@ov.com
  54.  
  55.